<?php
header ("Content-Type:text/html; charset= utf-8");
require_once ('config.php');
require_once (WEBURL.'/include/conn.php');
require_once (WEBURL.'/login_status_check.php');
if(!isset($_POST['article_id'])){
	echo "forbidden!";
	exit();
}
$article_id=$_POST['article_id'];
if(!checkLogin()){
	$gotopage=base64_encode("article_modify.php?article_id=".$article_id);
	header("Location:admin_login.php?gotopage=".$gotopage);
	
}
else{
	require_once (WEBURL.'/channel.class.php');
	require_once (WEBURL.'/time_to_timestamp.php');
	//require_once (XunSearchPath.'/sdk/php/lib/XS.php');
	$article_writer=$_POST['article_writer'];

	$article_title=addslashes($_POST['title']);
	$article_is_extends_url=0;
	$article_extends_url="";
	if(!empty($_POST['links'])){
		$article_is_extends_url=1;
		$article_extends_url=$_POST['external_links'];
	}
	$article_from=$_POST['from'];
	$article_main_channel=$_POST['main_channel'];
	$article_old_main_channel=$_POST['article_old_main_channel'];
	$article_has_picture=0;
	$article_picture_path="";
	if($_POST['picture']!=""){
		$article_has_picture=1;
		$article_picture_path=$_POST['picture'];
	}
	$article_clicked_times=$_POST['clicked_times'];
	$article_publish_time=timeToStimestamp($_POST['publish_time']);
	$article_content=base64_encode($_POST['article_content']);

	$current_time=time();
	$article_is_top=0;
	$article_is_top_time=0;
	if(!empty($_POST['is_top_status_change'])){
		$article_is_top=$_POST['istop'];
		if($article_is_top=="1"){
			$article_is_top_time_tmp=$_POST['is_top_time'];
			switch($article_is_top_time_tmp){
				case 0:
					$article_is_top_time=$current_time+60*60*24*7;
					break;
				case 1:
					$article_is_top_time=$current_time+60*60*24*30;
					break;
				case 2:
					$article_is_top_time=$current_time+60*60*24*30*3;
					break;
				case 3:
					$article_is_top_time=$current_time+60*60*24*30*5;
					break;
				case 4:
					$article_is_top_time=$current_time+60*60*24*365;
					break;
				case 5:
					$article_is_top_time= timeToStimestamp($_POST['custom_top_time']);
					break;
				default:
					break;

			}
		}

		$sql_modify_article="update article_normal set article_title='$article_title',article_is_extends_url=$article_is_extends_url,
	          article_extends_url='$article_extends_url',article_from='$article_from',article_main_channel=$article_main_channel,
           	  article_special_topic='',article_has_picture=$article_has_picture,article_picture_path='$article_picture_path',
	          article_click=$article_clicked_times,article_publish_time=$article_publish_time,article_modify_time=$current_time,
	          article_status=1,article_is_top=$article_is_top,article_top_time=$article_is_top_time,
	          article_content='$article_content' where article_id=$article_id;";

	}
	else{
		$sql_modify_article="update article_normal set article_title='$article_title',article_is_extends_url=$article_is_extends_url,
	          article_extends_url='$article_extends_url',article_from='$article_from',article_main_channel=$article_main_channel,
           	  article_special_topic='',article_has_picture=$article_has_picture,article_picture_path='$article_picture_path',
	          article_click=$article_clicked_times,article_publish_time=$article_publish_time,article_modify_time=$current_time,
	          article_status=1,article_content='$article_content' where article_id=$article_id;";
	}
	//echo $sql_modify_article;
	$result_modify_article=mysql_query($sql_modify_article) or die(mysql_error());
	if($result_modify_article){
		/*更新搜索表 */
		$article_content=@strip_tags(base64_decode($article_content));
		$article_content=str_replace('&nbsp', '', $article_content);
		$article_content=str_replace('&ldquo', '', $article_content);
		$article_content=str_replace('&rdquo', '', $article_content);
		$article_content=str_replace(';', '', $article_content);
		$article_content=str_replace('；', '', $article_content);
		$article_content=@addslashes($article_content);
		$sql_update="update search set article_title='$article_title',article_from='$article_from',article_main_channel=$article_main_channel,
	          article_publish_time=$article_publish_time,article_modify_time=$current_time,article_content='$article_content' where id=$article_id;";
		$result_update=mysql_query($sql_update) or die(mysql_error());
		/*更新索引 
		$xs = new XS('sys');
		$index = $xs->index;
		$data = array(
         'id' => $article_id,
         'article_title'=> $article_title,
         'article_main_channel'=> $article_main_channel,
         'article_publish_time'=> $article_publish_time,
         'article_modify_time'=> $current_time,
         'article_from'=> $article_from,
         'article_content'=> $article_content 
		);
		// 创建文档对象
		$doc = new XSDocument;
		$doc->setFields($data);

		// 修改索引
		$index->update($doc);
		*/
	echo "<script language=JavaScript>alert('修改文章成功！');history.go(-2);</script>";
}
}
